package cn.bblocks.common.i18n.demo;

import cn.bblocks.common.i18n.I;
import cn.bblocks.common.i18n.I18nHolder;
import cn.bblocks.common.i18n.demo.config.SpringContextUtils;
import cn.bblocks.common.i18n.repository.I18nLocaleHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.MessageSource;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.Arrays;
import java.util.Locale;

/**
 * bb-i18n整合SpringBoot 示例
 * @author Jin
 *
 */
@Slf4j
@SpringBootApplication
public class I18nDemoApplication2 implements ApplicationRunner {

	public static void main(String[] args) {
		SpringApplication.run(I18nDemoApplication2.class, args);
	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		log.info("项目启动成功》》》》》》I18nDemo2");


		I18nLocaleHolder i18nLocaleHolder = (I18nLocaleHolder)SpringContextUtils.getApplicationContext().getBean(I18nLocaleHolder.class);
		System.out.println("=======================>");

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("en"));
		System.out.println(I.n("err01"));

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("zh-CN"));
		System.out.println(I.n("err01"));

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("en"));
		System.out.println(I.n("err02"));

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("zh-CN"));
		System.out.println(I.n("err02"));


		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("en"));
		System.out.println(I.n("A00001","jin"));

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("zh-CN"));
		System.out.println(I.n("A00001","金"));


		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("en-US"));
		System.out.println(I.n("A00002","jin"));

		i18nLocaleHolder.setThreadLocale(Locale.forLanguageTag("zh-CN"));
		System.out.println(I.n("A00002","金"));


	}

}
